axios.defaults.baseURL= 'http://api-breakingnews-web.itheima.net'

axios.interceptors.request.use(function(config){
    // console.log(config);
    if(config.url.indexOf('/my') !== -1){
        config.headers.Authorization = localStorage.getItem('token')
        
    }
    return config
},function(error){
    return Promise.reject(error)
})
// 添加相应拦截器
axios.interceptors.response.use(function(response){
    // console.log(response);
    if(response.data.message === "身份认证失败！"){
        // 认证失败跳转到登录页面销毁token
        location.href='/login.html'
        localStorage.removeItem('token')
        return
    }
    return response
},function(error){
    return Promise.reject(error)
})
